import axios from './axios.js'

export default {
	//获取登录状态
	async connect() {
		await axios.post('/api/connect');
	},
	//登录
	async login(username, password) {
		return await axios.post('/api/user/login', {
			username,
			password
		})
	},
	//退出登录
	async outLogin() {
		return await axios.post('/api/user/outlogin')
	},
	//注册
	async register(username, password) {
		return await axios.post('/api/user/register', {
			username,
			password
		})
	},
	//上传文件
	async upload(formdata){
		return await axios.post('/api/upload', formdata, {
			headers:{
				'Content-Type':'multipart/form-data'
			}
		})
	},
	//获取用户信息
	async userInfo(){
		return await axios.post('/api/user/info')
	},
	//创建表    body = { * name[str], ? power_role[int], ? index[int] }
	async createTable(name, power_role, index) {
		return await axios.post('/api/table/create', {
			name,
			power_role,
			index
		})
	},
	//导入excel表 
	async importTable(name, fields, rows) {
		return await axios.post('/api/table/import', {
			name,
			fields,
			rows,
		})
	},

	//查询表 body = { ? id[int], ? name[str], ? page[int], ? pageSize[int] }参数选填
	async getTable() {
		return await axios.post('/api/table/query')
	},
	//修改表项目
	async updateTable(id, name, power_role, index) {
		return await axios.post('/api/table/update', {
			id,
			name,
			power_role,
			index
		})
	},
	//删除表
	async deleteTable(ids) {
		return await axios.post('/api/table/delete', {
			ids
		})
	},
	//增加表字段
	async addField(table_id,name,type,index, is_search, must_search, show_search) {
		return await axios.post('/api/field/add', {
			table_id,
			name,
			type,
			index,
			is_search,
			must_search,
			show_search
		})
	},
	//查询表字段
	async getField(table_id) {
		return await axios.post('/api/field/query', {
			table_id
		})
	},
	//删除表字段
	async deleteField(ids) {
		return await axios.post('/api/field/delete', {
			ids
		})
	},
	//修改表字段
	async updateField(id, name,type,index,is_search,must_search,show_search) {
		return await axios.post('/api/field/update', {
			id,
			name,
			type,
			index,
			is_search,
			must_search,
			show_search
		})
	},
	//插入数据行 rows是存对象二维数组,[[],[]]
	async addRows(table_id,row,rows) {
		return await axios.post('/api/row/add', {
			table_id,
			row,
			rows,
		})
	},
	//删除一行  id改为数组 方便批量操作
	async deleteRows(ids) {
		return await axios.post('/api/row/delete', {
			ids
		})
	},
	//修改数据 id改为数组形式 方便批量操作
	async updateRows(id, rows) {
		return await axios.post('/api/row/update', {
			id,
			rows
		})
	},
	//获取当前页显示数据行page为页码,pagSize为每页最大显示数量
	async getRows(table_id,id, page, pageSize) {
		return await axios.post('/api/row/query', {
			table_id,
			id,
			page,
			pageSize
		})
	}
}
